<%@page import="com.situ.web.entity.User"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="com.situ.web.entity.Student"%>
<%@page import="java.util.List"%>
<%@page import="com.situ.web.entity.PageBean"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href="bootstrap-3.3.7-dist/css/bootstrap.css" />
<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/util.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<a href="${pageContext.request.contextPath}/online_user_list.jsp"
		class="btn btn-success">在线用户列表</a>
	<br>
	<a 
		class="btn btn-success" onclick="insert()">添加</a>
	<br> 欢迎:${user.name }
	<a href="javascript:void(0)" onclick="logout1()"
		class="btn btn-success">注销</a>
	<form
		action="${pageContext.request.contextPath }/student?method=selectById"
		method="post">
		<input type="text" name="id"> <input type="submit"
			value="根据id查询">
	</form>
	<br>
	<form
		action="${pageContext.request.contextPath }/student?method=search"
		method="post">
		<input type="text" name="searchName"> <input type="submit"
			value="模糊查询">
	</form>
	<br>
	<table
		class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>年龄</td>
			<td>性别</td>
			<td>班级ID</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<c:forEach items="${pageBean.list }" var="student">
			<tr>
				<td>${student.id }</td>
				<td>${student.name }</td>
				<td>${student.age }</td>
				<td>${student.gender }</td>
				<td>${student.banjiId }</td>
				<td><a href="javascript:void(0)" class="btn btn-success"
					onclick="deleteById(${student.id })">删除</a></td>
				<td><a href="javascript:void(0)" class="btn btn-success"
					onclick="selectById(${student.id })">修改</a></td>
			</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
		<ul class="pagination">
			<c:if test="${pageBean.pageNo==1}">
				<li class="disabled"><a href="#" aria-label="Previous"> <span
						aria-hidden="true">&laquo;</span>
				</a></li>
			</c:if>
			<c:if test="${pageBean.pageNo!=1}">
				<li><a
					href="${pageContext.request.contextPath }/student?method=pageList&pageNo=${pageBean.pageNo-1}"
					class="btn btn-success" aria-label="Previous"> <span
						aria-hidden="true">&laquo;</span>
				</a></li>
			</c:if>

			<c:forEach begin="1" end="${pageBean.totalPage}" var="i">
				<c:if test="${pageBean.pageNo==i}">
					<li class="active"><a href="#">${i}</a></li>
				</c:if>
				<c:if test="${pageBean.pageNo!=i}">
					<li><a
						href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${i}">${i}</a></li>
				</c:if>
			</c:forEach>
			<c:if test="${pageBean.pageNo==pageBean.totalPage }">
				<li class="disabled"><a href="#" aria-label="Previous"> <span
						aria-hidden="true">&raquo;</span>
				</a></li>
			</c:if>
			<c:if test="${pageBean.pageNo!=pageBean.totalPage }">
				<li><a
					href="${pageContext.request.contextPath }/student?method=pageList&pageNo=${pageBean.pageNo-1}&pageSize=3"
					class="btn btn-success" aria-label="Previous"> <span
						aria-hidden="true">&raquo;</span>
				</a></li>
			</c:if>
		</ul>
	</nav>

</body>

<script type="text/javascript">


	function insert(){
		
		layer.open(
				{type:2,
					title : "添加学生",	
				area:["600px","400px"],
				content : "${pageContext.request.contextPath}/student_insert.jsp"
				});
	};	


	function deleteById(id){
			 
		layer.confirm(
				"您确认要删除么？",
				function(index) {
					console.log(index);
					$.post(
						"${pageContext.request.contextPath}/student?method=deleteById&id=" + id,
						function(jsonObj){
							if(jsonObj.code == util.SUCCESS) {
								mylayer.successMsg(jsonObj.msg);
								location.reload();
							} else {
								mylayer.errorMsg(jsonObj.msg);
							}
						},
						"json"
					);
				}
			);		 
		} 
		
		function selectById(id){
			
			layer.open(
					{type:2,
						title : "修改学生",	
					area:["600px","400px"],
					content : "${pageContext.request.contextPath}/student?method=selectById2&id="+id
					});
		}
		
		function logout1(){
			
			 layer.confirm(
						"您确定要注销吗？",
						{icon:3,title:"确认注销"},
						function(index){
							location.href = "/JavaWeb1907/user?method=logout";
							layer.close(index);
						}
					 )};
		
	</script>
</html>